// miniprogram/pages/user/detail/myCourse/myCourse.js
import axios from '../../../../utils/axios'
import {
  formatDate
} from '../../../../utils/utils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    courseList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let res = await axios({
      url: '/api/classroom/self',
      header: {
        'Authorization': wx.getStorageSync('token')
      }
    });
    console.log(res.data.content);
    res.data.content = res.data.content.filter(item => item.isDel != true);
    console.log(res.data.content);
    res.data.content.forEach(item => {
      [item.startTime, item.createTime, item.updateTime] = [
        formatDate('YY-mm-dd HH:MM:SS', new Date(item.startTime)),
        formatDate('YY-mm-dd HH:MM:SS', new Date(item.createTime)),
        formatDate('YY-mm-dd HH:MM:SS', new Date(item.updateTime))
      ];
    });
    this.setData({
      courseList: res.data.content
    })
  },
  classDetail(e) {
    // console.log(e.currentTarget.dataset.data);
    let classData = e.currentTarget.dataset.data;
    wx.navigateTo({
      url: './classDetail/classDetail',
      success: (res) => {
        res.eventChannel.emit('classDetail', {
          data: classData
        })
      },
    });
  }

})